export function getCitySeries(cityData, cityMarkData, formatter) {
  return {
    name: "cityPoint-north",
    type: "scatter",
    coordinateSystem: "geo",
    symbol: `image://${require("@/assets/city.svg")}`,
    symbolSize: [0, 0],
    label: {
      show: false,
      position: "bottom",
      formatter: "{b}",
      textStyle: {
        color: "#000"
        // fontSize: 16,
        // padding: 0
      }
    },
    data: cityData,
    // todo 其他大区只显示地点名称，不显示弹窗
    markPoint: {
      symbol: "circle",
      symbolSize: [0, 0],
      label: {
        show: false,
        fontSize: 12,
        color: "#fff",
        position: "inside",
        backgroundColor: "#97bdf9",
        padding: 8,
        align: "left",
        lineHeight: 17, // 增加行高以保持行间距
        offset: [-10, -30], // 调整偏移量，增加与符号的距离
        formatter: formatter
      },
      data: cityMarkData
    }
  };
}

export function getUserSeries(userData, userMarkData, formatter) {
  return {
    name: "userPoint-north",
    type: "scatter",
    coordinateSystem: "geo",
    symbol: `image://${require("@/assets/user.svg")}`,
    symbolSize: [0, 0],
    // 数据点不能被点击
    // silent:false,
    label: {
      show: false,
      formatter: "{b}",
      position: "bottom",
      textStyle: {
        color: "#000"
      }
    },
    data: userData,

    markPoint: {
      itemStyle: {
        // 去除背景色，设置为 transparent
        color: "transparent"
      },
      label: {
        show: false,
        fontSize: 12,
        color: "#fff",
        position: "inside",
        backgroundColor: "#97bdf9",
        padding: 8,
        align: "left",
        lineHeight: 15, // 增加行高以防止重叠
        offset: [-10, -25], // 增加偏移量以增加上下距离
        formatter: formatter
      },

      symbol: "circle",
      symbolSize: [0, 0],
      data: userMarkData
    }
  };
}
export function getDataSeries(userData, presMarkData, formatter) {
  return {
    name: "userPoint-north",
    type: "scatter",
    coordinateSystem: "geo",
    symbol: `image://${require("@/assets/suction.svg")}`,
    symbolSize: [0, 0],
    // 数据点不能被点击
    // silent: true,
    label: {
      show: false,
      formatter: "{b}",
      position: "bottom",
      textStyle: {
        color: "#000"
      }
    },
    data: userData,

    markPoint: {
      itemStyle: {
        // 去除背景色，设置为 transparent
        color: "transparent"
      },
      label: {
        show: false,
        fontSize: 12,
        color: "#fff",
        position: "inside",
        backgroundColor: "#97bdf9",
        padding: 8,
        align: "left",
        lineHeight: 15, // 增加行高以防止重叠
        offset: [-10, -25], // 增加偏移量以增加上下距离
        formatter: formatter
      },

      symbol: "circle",
      symbolSize: [0, 0],
      data: presMarkData
    }
  };
}
export function getPipeSeries(lineData, index = "") {
  return {
    name: "pipeLine-" + index,
    type: "lines",
    coordinateSystem: "geo",
    polyline: false,
    show: true,
    silent: true,
    lineStyle: {
      type: "solid",
      width: 0,
      opacity: 1,
      orient: "horizontal",
      curveness: 0.2
    },
    emphasis: {
      lineStyle: {
        type: "solid",
        width: 6,
        opacity: 1,
        orient: "horizontal",
        curveness: 20.2,
        normal: {
          color: "#00f", //线条颜色
          width: 5,
          curveness: 0.2
          // shadowColor: '#fff',
        }
      }
    },
    data: lineData
  };
}

export function getGeoConfig() {
  return {
    // 地图配置
    map: "china",
    center: null,
    zoom: 1.2,
    roam: false,
    show: true,
    scaleLimit: {
      min: 1.2,
      max: 12
    },
    regions: [
      {
        name: "东部",
        id: 20,
        center: [100.8062, 31.9208],
        label: {
          show: true
        },
        itemStyle: {
          areaColor: "#93C2FF",
          borderColor: "#2794FF",
          borderWidth: 1
        },
        emphasis: {
          itemStyle: {
            areaColor: "rgba(255,255,255,0)",
            borderColor: "#2794FF",
            borderWidth: 1
          }
        }
      },
      {
        name: "北部",
        id: 23,
        center: [120.4123, 39.9042],
        label: {
          show: true
        },
        itemStyle: {
          areaColor: "#6FADFF",
          borderColor: "#2794FF",
          borderWidth: 1
        },
        emphasis: {
          itemStyle: {
            areaColor: "#2794FF", // 点击后不改变颜色
            borderWidth: 1
          }
        }
      },
      {
        name: "西部",
        id: 25,
        center: [130.4123, 39.9042],
        label: {
          show: true,
          formatter: function(params) {
            // params 是一个对象，包含了当前区域的信息
            return "西部"; // 假设params.value存在
          }
        },
        itemStyle: {
          areaColor: "#F2F8FF",
          borderColor: "#2794FF",
          borderWidth: 1
        },
        emphasis: {
          itemStyle: {
            areaColor: "rgba(255,255,255,0)",
            borderColor: "#2794FF",
            borderWidth: 1
          }
        }
      },
      {
        name: "中部",
        id: 21,
        center: [140.4123, 39.9042],
        label: {
          show: true
        },
        itemStyle: {
          areaColor: "#BAD8FF",
          borderColor: "#2794FF",
          borderWidth: 1
        },
        emphasis: {
          itemStyle: {
            areaColor: "rgba(255,255,255,0)",
            borderColor: "#2794FF",
            borderWidth: 1
          }
        }
      },
      {
        name: "南部",
        id: 24,
        center: [150.4123, 39.9042],
        label: {
          show: true
        },
        itemStyle: {
          areaColor: "#E1EEFF",
          borderColor: "#2794FF",
          borderWidth: 1
        },
        emphasis: {
          itemStyle: {
            areaColor: "rgba(255,255,255,0)",
            borderColor: "#2794FF",
            borderWidth: 1
          }
        }
      }
    ],
    itemStyle: {
      shadowColor: "rgba(5, 17, 44, 0.10)",
      shadowBlur: 0
    }
  };
}

export function getWinterForecast(curTemp, winterForecast) {
  return {
    type: "effectScatter",
    coordinateSystem: "geo",
    symbol: "pin",
    symbolSize: 1,
    label: {
      show: true,
      formatter: params => {
        for (let i = 0; i < winterForecast.length; i++) {
          if (winterForecast[i].dispatcherId == params.data.id) {
            const temperature =
              winterForecast[i].temperatureData[5 + curTemp].temperature;
            const forecast =
              winterForecast[i].temperatureData[5 + curTemp].predictedGasUsage;
            return `\n${temperature}°C ${forecast}亿方`;
          }
        }
      },
      verticalAlign: "middle", // 垂直居中
      lineHeight: 30,
      color: "black", // 设置文字颜色为黑色
      fontWeight: 500
    },
    data: [
      { name: "东部", value: [115.187876, 33.898593], id: 20 },
      { name: "北部", value: [120.148013, 43.8059145], id: 23 },
      { name: "西部", value: [91.109405, 37.0153015], id: 25 },
      { name: "中部", value: [110.095, 29.17], id: 21 },
      { name: "南部", value: [107.0575085, 24.5317365], id: 24 }
    ]
  };
}

export function getExistLineIndex(series) {
  const map = new Map();
  for (let i = 0; i < series.length; i++) {
    const name = series[i].name;
    map.set(name, i);
  }
  return map.get("linePipe") === undefined ? -1 : map.get("linePipe");
  // // 判断是否已存在管线
  // const index = getExistLineIndex(this.options.series)
  // if (index >= 0) {
  //   this.options.series.splice(index, 1)
  // }
}
